package com.zmj.sy.mom.srv.aps.service.scheduler.inverted;

import com.zmj.sy.mom.srv.aps.bean.entity.order.Order;
import com.zmj.sy.mom.srv.aps.utils.ApsConstant;
import lombok.Getter;
import lombok.Setter;

import java.time.LocalDateTime;
import java.util.Set;

/**
 * 倒排排产上下文，用于存储倒排参数
 */
@Getter
@Setter
public class InvertedScheduleContext {

    public static final String SORTED_PLANED_MONTH_AND_SEQ = "planedMonth+seq";

    public static final String RELATIONSHIP_CONSTRUCTION = "construction";

    public static final String BATCH_METHOD_SINGLE = "single";

    public static final String ORDER_METHOD_TRANSLATE = "translate";

    public static final String NO_SHIFT_STRATEGY_VALID = "valid";

    private Set<Order> orders;

    /**
     * 订单排序方式
     * 1、null 无序
     * 2、planedMonth 订单计划月排序
     */
    private String sorted;

    /**
     * 排产锁
     */
    private String lock;

    /**
     * 参考时间
     */
    private LocalDateTime referenceTime;

    /**
     * 批次内排产方法
     * 1、single 单件倒排
     */
    private String batchMethod;

    /**
     * 订单内排产方法
     * 1、translate 当前批次的排产基于前一批次进行平移
     */
    private String orderMethod;

    /**
     * 订单间的排产方法
     * 1、construction 同一的施工号的订单之间必须同时交付，不同施工号顺次排产
     */
    private String relationship;

    /**
     * 无班次时的排产策略
     * 1、valid 默认正常上班
     */
    private String noShiftStrategy;

    /**
     * 月度排产上下文配置
     */
    public static InvertedScheduleContext monthSchedule(LocalDateTime firstBatchDeliveryTime) {
        InvertedScheduleContext context = new InvertedScheduleContext();
        context.setSorted(SORTED_PLANED_MONTH_AND_SEQ);
        context.setLock(ApsConstant.APS_SCHEDULING_LOCK);
        context.setReferenceTime(firstBatchDeliveryTime);
        context.setBatchMethod(BATCH_METHOD_SINGLE);
        context.setOrderMethod(ORDER_METHOD_TRANSLATE);
        context.setRelationship(RELATIONSHIP_CONSTRUCTION);
        context.setNoShiftStrategy(NO_SHIFT_STRATEGY_VALID);
        return context;
    }

}
